/*
    Project:        Home Power Control
    File:           HPCValue.h
    Author:         christian@karunamusic.at
    Date:           01.2015
    Description:    A value class of all types for use with the sensors.
 */

#ifndef HPCVALUE_H
#define HPCVALUE_H

#include <QVariant>

/** \brief A value class for all numeric types for use with the sensors.
 */
class HPCValue : public QObject
{
    Q_OBJECT
public:
    /** \brief Constructor.
     */
    HPCValue();
    /** \brief Constructor.
     *
     * \param val The value as QVariant.
     */
    HPCValue( const QVariant& v );
    /** \brief Copy Constructor.
     *
     * \param ref The object to copy.
     */
    HPCValue( const HPCValue& v );
    /** \brief Destructor.
     */
    virtual ~HPCValue();

    /** \brief Get the value as QVariant.
     *
     * \return QVariant.
     */
    inline QVariant& V()
        { return m_Var; }

    /** \brief Get the timestamp.
     *
     * \return The timestamp as QString.
     */
    inline uint TimeStamp() const
        { return m_TimeStamp; }

    /** \brief Value is valid.
     *
     * \return true if value is at least one time assigned, otherwise false.
     */
    inline uint isValid() const
        { return m_Var.isValid(); }

    /** \brief Assignment operator.
     *
     * \param v The object to copy.
     * \return HPCValue.
     */
    HPCValue& operator = ( const HPCValue& v );

signals:
    /** \brief Is emitted if the value has changed.
     *
     * \param v The changed value.
     */
    void changed( HPCValue& v );

public slots:
    /** \brief Set the value from QVariant.
     *
     * \param v QVariant.
     */
    void V( const QVariant& v );

protected:
    QVariant m_Var; /**< The value. */
    uint m_TimeStamp; /**< The timestamp. */
};

#endif // HPCVALUE_H
